<?php

class Application_Form_File extends Zend_Form
{
    public function init()
    {
        $this->setAttrib('enctype', 'multipart/form-data');
        $this->setMethod('POST');
        $this->setAction(Zend_Registry::get('view')->fixUrl('file/add'));
        
        $file = new Zend_Form_Element_File('file');
        $file->setLabel('File')
                ->setDestination(ROOT_DIR.'/'.Application_Model_File::UPLOAD_DIR)
        //        ->addValidator('Count', true, array('min' => 1, 'max' => 5))
                ->addValidator('Count', true, 1)
                ->addValidator('Size', true, 2097152)      //   2 MB
                ->addValidator('Extension', true, 'jpg,png,gif')
                ->addValidator(new Application_Form_FileValidator())
                ->addDecorator(new Application_Form_FileDecorator())
                ->setRequired(true)
        //        ->setMultiFile(5)
                ->setValueDisabled(true);   // do not receive file during getValues() call
  
         $submit=new Zend_Form_Element_Submit('submit');
         $submit->setValue('Save')
                ->setLabel('')
                ->addDecorator(new Application_Form_FileDecorator());
               
         $csrf=new Zend_Form_Element_Hash('csrf',array('salt' => 'fileUpload'));
         $csrf->setOptions(array(
                            'ignore' => true,
                        ))
              ->addDecorator(new Application_Form_FileDecorator());
              
        $this->addElements(
            array(
                $file,
                $submit,
                $csrf
                )
        );
    }
}

